package io.mft.runtime.function.process.executor;

import io.mft.api.domain.Regulation;
import io.mft.commons.function.ExecuteReturn;
import io.mft.runtime.MFTApiExecutor;
import io.mft.runtime.function.ApiContext;
import io.mft.runtime.function.ApiFunctionRequest;
import io.mft.runtime.function.ApiFunctionResponse;
import io.mft.runtime.function.process.ApiFunctionProcessExecutor;

/**
 * 逻辑处理执行器
 * 
 * @说明：TODO
 * @类型名称：LogicProcessExecutor
 * @创建者: 胡常建
 * @创建时间: 2021年1月26日 下午4:42:49
 * @修改者: 胡常建
 * @修改时间: 2021年1月26日 下午4:42:49
 */
public class LogicProcessExecutor extends ApiFunctionProcessExecutor<Regulation> {

	@Override
	public ExecuteReturn doExecute(ApiContext context) {
		if (context.isSuccessReadCache()) {
			return ExecuteReturn.builder().build();
		}
		Regulation regulation = getRegulation();
		switch (regulation.getType()) {
		case java:
			String[] ids = regulation.getValue().split("\\.");
			return executePluginFunction(context, regulation, ids[0], ids[1]);
		case ql:
			return ExecuteReturn.builder().build();
		case api:
			ApiFunctionRequest request=new ApiFunctionRequest(context.getRequest().getRequestValue());
			ApiFunctionResponse response=MFTApiExecutor.getInstance().execute(regulation.getValue(), request);
			ExecuteReturn executeReturn=ExecuteReturn.builder().code(response.getErrorNo()).message(response.getErrorInfo()).build();
			return executeReturn;
		default:
			return ExecuteReturn.builder().build();
		}

	}

}
